package com.cq.hd.member.controller;

import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbWithdrawalBillApi;
import com.cq.hd.member.api.dto.*;
import com.cq.hd.member.api.vo.*;
import com.cq.hd.member.service.TbAutoWithdrawalRecordService;
import com.cq.hd.member.service.TbWithdrawalBillService;
import com.cq.hd.member.service.TbWithdrawalCheckBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 提现记录表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2024-01-28
 */
@RestController
public class TbWithdrawalBillController implements TbWithdrawalBillApi {

    @Autowired
    private TbWithdrawalBillService withdrawalBillService;
    @Autowired
    private TbWithdrawalCheckBillService withdrawalCheckBillService;
    @Autowired
    private TbAutoWithdrawalRecordService autoWithdrawalRecordService;

    @Override
    public Result<Boolean> apply(@RequestBody WithdrawalApplyDto withdrawalApplyDto) {
        return ResultGenerator.success(withdrawalBillService.apply(withdrawalApplyDto));
    }

    @Override
    public Result<Boolean> applyV2(WithdrawalApplyV2Dto withdrawalApplyV2Dto) {
        return ResultGenerator.success(withdrawalBillService.applyV2(withdrawalApplyV2Dto));
    }

    @Override
    public Result<Page<WithdrawalApplyPageVo>> pageWithdrawalBill(WithdrawalApplyPageDto withdrawalApplyPageDto) {
        return ResultGenerator.success(withdrawalBillService.pageWithdrawalBill(withdrawalApplyPageDto));
    }

    @Override
    public Result<Page<WithdrawalApplyPageVo>> pageMerchantWithdrawalBill(WithdrawalApplyPageDto withdrawalApplyPageDto) {
        return ResultGenerator.success(withdrawalBillService.pageMerchantWithdrawalBill(withdrawalApplyPageDto));
    }

    @Override
    public Result<Page<AdminWithdrawalApplyPageVo>> pageAdminWithdrawalBill(AdminWithdrawalApplyPageDto adminWithdrawalApplyPageDto) {
        return ResultGenerator.success(withdrawalBillService.pageAdminWithdrawalBill(adminWithdrawalApplyPageDto));
    }

    @Override
    public Result<Boolean> audit(@RequestBody AdminWithdrawalApplyAuditDto adminWithdrawalApplyAuditDto) {
        return ResultGenerator.success(withdrawalBillService.audit(adminWithdrawalApplyAuditDto));
    }

    @Override
    public Result<AdminWithdrawalAmtVo> getWithdrawalAmt(AdminWithdrawalApplyPageDto adminWithdrawalApplyPageDto) {
        return ResultGenerator.success(withdrawalBillService.getWithdrawalAmt(adminWithdrawalApplyPageDto));
    }

    @Override
    public Result<Boolean> consumerWithdrawalMsg(Long id) {
        return ResultGenerator.success(withdrawalBillService.consumerWithdrawalMsg(id));
    }

    @Override
    public Result<List<WithdrawalBillVo>> listByDto(WithdrawalBillDto withdrawalBillDto) {
        return ResultGenerator.success(withdrawalBillService.listByDto(withdrawalBillDto));
    }

    @Override
    public Result<Boolean> scanWithdrawalBill() {
        return ResultGenerator.success(withdrawalBillService.scanWithdrawalBill());
    }

    @Override
    public Result<SubsidyNoEnoughVo> getSubsidyNoEnough(Long merchantId) {
        return ResultGenerator.success(withdrawalBillService.getSubsidyNoEnough(merchantId));
    }

    @Override
    public Result<BigDecimal> getMerchantAccWithdrawalAmt(Long merchantId) {
        return ResultGenerator.success(withdrawalBillService.getMerchantAccWithdrawalAmt(merchantId));
    }

    @Override
    public Result<Boolean> checkBillConfirm(CheckBillConfirmDto checkBillConfirmDto) {
        return ResultGenerator.success(withdrawalBillService.checkBillConfirm(checkBillConfirmDto.getCheckBillId()));
    }

    @Override
    public Result<WithdrawalCheckBillVo> checkBillInfo(Long checkBillId) {
        return ResultGenerator.success(withdrawalCheckBillService.getDetail(checkBillId));
    }

    @Override
    public Result<Boolean> uploadPaymentVoucher(AdminWithdrawalBillPaymentVoucherDto adminWithdrawalBillPaymentVoucherDto) {
        return ResultGenerator.success(withdrawalBillService.uploadPaymentVoucher(adminWithdrawalBillPaymentVoucherDto));
    }

    @Override
    public Result<TbWithdrawalBillPaymentVoucherVo> getPaymentVoucher(Long withdrawalBillId) {
        return ResultGenerator.success(withdrawalBillService.getPaymentVoucher(withdrawalBillId));
    }

    @Override
    public Result<WithdrawalCheckBillInitVo> initCheck(Long withdrawalId) {
        return ResultGenerator.success(withdrawalBillService.initCheck(withdrawalId));
    }

    @Override
    public Result<WithdrawalCheckBillInitVo> checkInfo(Long checkBillId) {
        return ResultGenerator.success(withdrawalBillService.checkInfo(checkBillId));
    }

    @Override
    public Result<WithdrawalCheckBillPreVo> preCheckBill(Long checkBillId) {
        return ResultGenerator.success(withdrawalCheckBillService.preCheckBill(checkBillId));
    }

    @Override
    public Result<Boolean> saveCheckBill(WithdrawalCheckBillSaveDto checkBillSaveDto) {
        return ResultGenerator.success(withdrawalBillService.saveCheckBill(checkBillSaveDto));
    }

    @Override
    public Result<BigDecimal> sumAutoWithdrawalAmount(Long merchantId, Integer state) {
        return ResultGenerator.success(autoWithdrawalRecordService.sumWithdrawalAmountByState(merchantId, state));
    }
}
